#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,urllib,urllib2,imp,os
import xbmc,xbmcplugin,xbmcgui
path=xbmc.translatePath(os.path.join(os.path.normpath(os.path.join(os.getcwd(),os.pardir,os.pardir)),'hoster'+os.sep+'oracle'+os.sep+'interface2.py'))
interface2=imp.load_source("interface2", "interface2.py", open(path,'r'))


#--------------------------------------------------------------------------------------------------
#author:
#elypter
#-mail:elypter@yahoo.de
#
#for details look at readme.txt


#--------------------------------------------------------------------------------------------------
debug=1
dstr="##*oracle*default*"

def get_verion():
	#or look at the filename
	return 2
	
	
#--------------------------------------------------------------------------------------------------	
def get_params():
		param=[]
		paramstring=sys.argv[2]
		if len(paramstring)>=2:
				params=sys.argv[2]
				cleanedparams=params.replace('?','')
				if (params[len(params)-1]=='/'):
						params=params[0:len(params)-2]
				pairsofparams=cleanedparams.split('&')
				param={}
				for i in range(len(pairsofparams)):
						splitparams={}
						splitparams=pairsofparams[i].split('=')
						if (len(splitparams))==2:
								param[splitparams[0]]=splitparams[1]
								
		return param






#[entry point]		
params=get_params()
url=None
name=None
mode=None

#url=urllib.unquote_plus(params["url"])
#print "url"+url

try:
		url=urllib.unquote_plus(params["url"])
except:
		pass
try:
		name=urllib.unquote_plus(params["name"])
except:
		pass
try:
		mode=int(params["mode"])
except:
		pass

if debug > 0: print dstr+" ARGV2:"+str(sys.argv[2])
if debug > 0: print dstr+" Mode: "+str(mode)
if debug > 0: print dstr+" URL: "+str(url)
if debug > 0: print dstr+" Name: "+str(name)

#finding out wich method should be launched
if mode==None :
	print "launching* mode=None"
	

elif mode == 1:
	if debug > 0: print dstr+" launching: mode=1 | MIRROR_LIST("+str(url)+")"
	interface2.MIRROR_LIST(url)
	
elif mode == 2:
	if debug > 0: print dstr+" launching: mode=2 | LINK_LIST("+str(url)+")"
	interface2.LINK_LIST(url)
	xbmcplugin.endOfDirectory(int(sys.argv[1]))

elif mode == 3:
	if debug > 0: print dstr+" launching: mode=3 | CAPTCHA_LIST("+str(url)+")"
	interface2.CAPTCHA_LIST(url)
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
	
elif mode == 4:
	if debug > 0: print dstr+" launching: mode=4 | ACTION_LIST("+str(url)+")"
	interface2.ACTION_LIST(url)
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
	
elif mode == 5:
	if debug > 0: print dstr+" launching: mode=5 | DOWNLOAD_LIST("+str(url)+")"
	interface2.DOWNLOAD_LIST(url)
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
	
elif mode == 6:
	if debug > 0: print dstr+" launching: mode=6 | HISTORY_LIST("+str(url)+")"
	interface2.HISTORY_LIST(url)
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
	
elif mode == 7:
	if debug > 0: print dstr+" launching: mode=7 | SETTINGS_LIST("+str(url)+")"
	interface2.SETTINGS_LIST(url)
	xbmcplugin.endOfDirectory(int(sys.argv[1]))
